//
//  AnnotationViewController.m
//  Annotation
//
//  Created by Lion User on 06/07/2012.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AnnotationViewController.h"
#import "Annotation.h"

@interface AnnotationViewController ()

@end

@implementation AnnotationViewController

@synthesize mapView;

-(void) viewDidLoad{
    [super viewDidLoad];
    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];
    [mapView setDelegate:self];
    
    MKCoordinateRegion bigBen={{0.0,0.0},{0.0,0.0}};
    bigBen.center.latitude =51.50063;
    bigBen.center.longitude =-0.124629;
    bigBen.span.latitudeDelta=0.02f;
    bigBen.span.longitudeDelta=0.03f;
    [mapView setRegion:bigBen animated:YES];
    
    Annotation *ann1=[[Annotation alloc] init];
    ann1.title=@"Big Ben";
    ann1.subtitle=@"A wonderful place";
    ann1.coordinate=bigBen.center;
    [mapView addAnnotation: ann1];
    
    MKCoordinateRegion Bridge={{0.0,0.0},{0.0,0.0}};
    Bridge.center.latitude =51.50080;
    Bridge.center.longitude =-0.120914;
    Bridge.span.latitudeDelta=0.02f;
    Bridge.span.longitudeDelta=0.02f;
    [mapView setRegion:Bridge animated:YES];

    Annotation *ann2=[[Annotation alloc] init];
    ann2.title=@"Westminser Bridge";
    ann2.subtitle=@"A beautiful place";
    ann2.coordinate=Bridge.center;
    [mapView addAnnotation: ann2];
    
}

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
    MKPinAnnotationView *MyPin =[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
    MyPin.pinColor =MKPinAnnotationColorPurple;
    
    UIButton *advertButton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [advertButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
   
    MyPin.rightCalloutAccessoryView =advertButton;
    MyPin.draggable=NO;
    MyPin.highlighted =YES;
    MyPin.animatesDrop= true;
    MyPin.canShowCallout = YES;
    
    return MyPin;
    
}

-(void)button:(id)sender{
    
    NSLog(@"button action");
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
